<div class="sc-cnt-publicacao">
        
   
    <div class="content-tb nowid e-cnt-men">
        <div class="tl-pag">Simulado</div>
        
        <table class="nrmprd">          
        <?php foreach($this->result as $key => $row){ ?>
            <tr>
                <td style="width: 200px">
                    <?php echo $row['PLS_NOM']; ?>
                </td>    
                <td style="width: 200px">
                    <div class="lst_exe_inf">
                        Publicado<br/>
                        <span class="inf_txt">
                            <?php echo Datetools::amd_dma($row['PLS_DAT']); ?> 
                        </span>
                        <?php /*
                        &nbsp; às &nbsp; 
                        <span class="inf_txt">
                            <?php echo Datetools::hora_hm($row['PLS_HOR']); ?>
                        </span>
                        */ ?>
                    </div>
                </td>
                <?php /*
                <td style="width: 100px" align="center">
                    <div class="lst_exe_inf">
                        Colocação<br/>
                        <span class="inf_txt">
                            <?php echo $row['PLA_POS']; ?>º
                        </span>
                    </div>
                </td>
                */ ?>
                <td style="width: 100px" align="center">
                    <div class="lst_exe_inf">
                        Nota<br/>
                        <span class="inf_txt">
                            <?php echo $row['PLA_POR']; ?>
                        </span>
                    </div>
                </td>
                <td class="bc bc-cmp"><a class="btn btn-cmp" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['PLS_ID'])); ?>">Grade de respostas</a></td>
                <?php if($row['PLS_STAALU'] == 1){ ?>
                <td class="bc bc-cmp icn_exp_tb" itemid="<?php echo $row['PLS_ID']?>"><a class="btn btn-cmp" href="javascript:void(0)">Resultado</a></td>
                <?php } ?>
            </tr>
            <?php if($row['PLS_STAALU'] == 1){ ?>
            <tr class="cntsubitem-<?php echo $row['PLS_ID']?>" style="display:none;">
                <td colspan="5">
                    <?php /*
                    <span class="icn_exp_cont rot90" itemid="<?php echo $row['PLS_ID']?>"></span> Resultado
                    <ul class="lst_res_alu cntsubitem-<?php echo $row['PLS_ID']?>">
                        
                    <?php 
                        $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM '
                                .' FROM PUBSIM_RANALU p, DISCIPLINA d '
                                .' WHERE p.PLS_ID = ' . $row['PLS_ID']
                                .' AND p.PLA_REDID = d.DCP_ID '
                                .' AND p.ALU_ID = ' . $row['ALU_ID'];
                        $alu = $this->db->fetchRow($query);
                        if($alu['PLA_REDID'] > 0){
                             echo '<li>'.$alu['DCP_NOM'].'<span class="port">'.$alu['PLA_REDNTAPSO'].'</span></li>';
                        } 
                    ?>    
                    
                    <?php
                    
                        $query = 'SELECT SQL_CACHE *, d.DCP_NOM ' 
                                .' FROM PUBSIM_DISALU r, DISCIPLINA d '
                                .' WHERE r.PLS_ID = '.$row['PLS_ID']
                                .' AND r.DCP_ID = d.DCP_ID '
                                .' AND r.ALU_ID = ' . $row['ALU_ID'];
                        $disc = $this->db->fetchAll($query);
                        foreach($disc as $dis){
                            echo '<li>'.$dis['DCP_NOM'].'<span class="port">'.$dis['PQD_ACR'].'</span></li>';
                        }
                        
                    ?>
                    <ul>
                    */?>
                    <?php
                    
                    $query = 'SELECT SQL_CACHE p.*,d.DCP_NOM, d.DCP_NOMABV ' 
                            .' FROM PUBLICACAO_SIMULADO_GABARITO p, DISCIPLINA d '
                            .' WHERE p.DCP_ID = d.DCP_ID AND p.PLS_ID = '.$row['PLS_ID']
                            .' GROUP BY p.DCP_ID ASC'
                            .' ORDER BY p.PSG_QST ASC';
                    $result = $this->db->fetchAll($query);
                    
                    
                    $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM, d.DCP_NOMABV  '
                            .' FROM PUBSIM_RANALU p'
                            .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                            .' WHERE p.PLS_ID = ' . $row['PLS_ID']
                            .' ORDER BY PLA_POR DESC';
                    $mel = $this->db->fetchRow($query);
                    

                    ?>
                    <div class="lst_res_alu_nv">
                        <table style="width: 100% !important;">
                            <tr>
                                <th colspan="3">Desempenho</th>
                            </tr> 
                            <tr>
                                <th>Matéria</th>
                                <th>Acertos</th>
                                <th>Peso</th>
                            </tr> 
                            <?php 
                                $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM '
                                        .' FROM PUBSIM_RANALU p '
                                        .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                                        .' WHERE p.PLS_ID = ' . $row['PLS_ID']
                                        .' AND p.ALU_ID = ' . $row['ALU_ID'];
                                $alu = $this->db->fetchRow($query);
                                if($alu['PLA_REDID'] > 0){
                            ?>
                            <tr>
                                <td><?php echo $alu['DCP_NOM']; ?>¹</td>
                                <td align="center"><?php echo $alu['PLA_REDNTAPSO']; ?></td>
                                <td align="center"><?php echo tools::trunc_valor($alu['PLA_REDPSO'],0); ?></td>
                            </tr> 
                            <?php  } ?>

                            <?php 
                                foreach($result as $res_row){ 
                                    $qtd_acerto = 0;
                                    $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                                            . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                                            .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                                            .' AND p.PLS_ID = '.$row['PLS_ID'].' AND r.PLS_ID = '.$row['PLS_ID']
                                            .' AND r.ALU_ID = '.$row['ALU_ID']
                                            .' AND p.DCP_ID = r.DCP_ID '
                                            .' AND p.DCP_ID = '.$res_row['DCP_ID'].' AND r.DCP_ID = '.$res_row['DCP_ID']
                                            .' ORDER BY p.PSG_QST';
                                    $ress = $this->db->fetchAll($query);
                                    foreach($ress as $res){
                                        if($res['PSG_ALT'] == $res['PSR_ALT'] ){
                                            $qtd_acerto++;
                                        } 
                                    }
                                    if(count($ress) > 0){
                            ?>
                            <tr>
                                <td><?php echo $res_row['DCP_NOM']; ?></td>
                                <td align="center"><?php echo $qtd_acerto; ?></td>
                                <td align="center"><?php echo tools::trunc_valor($res_row['PSG_PES'],0); ?></td>
                            </tr> 
                                <?php } ?>
                            <?php } ?>
                        </table>    
                        <br>
                        <table style="width: 100% !important;">
                            <tr>
                                <th>Média</th>
                                <th>Classificação</th>
                            </tr> 
                            <tr>
                                <td align="center"><?php echo $alu['PLA_POR']; ?></td>
                                <td align="center"><?php echo $alu['PLA_POS']; ?></td>
                            </tr> 
                            <?php if($alu['PLA_REDID'] > 0){ ?>
                            <tr>
                                <td colspan="2">1. Nota da <?php echo $alu['DCP_NOM']; ?>: <?php echo $alu['PLA_REDNTA']; ?></td>
                            </tr>
                            <?php } ?>
                        </table>    
                        <br>
                        <table style="width: 100% !important;">
                            <tr>
                                <th colspan="12">Melhor Desempenho</th>
                            </tr>
                            <tr>
                            <?php 
                            $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM, d.DCP_NOMABV '
                                    .' FROM PUBSIM_RANALU p '
                                    .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                                    .' WHERE p.PLS_ID = ' . $row['PLS_ID']
                                    .' AND p.ALU_ID = ' . $row['ALU_ID'];

                            $mel_alu = $this->db->fetchRow($query);
                            if($mel_alu['PLA_REDID'] > 0){
                            ?>
                                <td align="center"><?php echo $mel_alu['DCP_NOMABV']; ?></td>
                            <?php  } ?>
                            <?php foreach($result as $res_row){ 
                                $qtd_acerto = 0;
                                $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                                        . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                                        .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                                        .' AND p.PLS_ID = '.$row['PLS_ID'].' AND r.PLS_ID = '.$row['PLS_ID']
                                        .' AND r.ALU_ID = '.$mel['ALU_ID']
                                        .' AND p.DCP_ID = r.DCP_ID '
                                        .' AND p.DCP_ID = '.$res_row['DCP_ID'].' AND r.DCP_ID = '.$res_row['DCP_ID']
                                        .' ORDER BY p.PSG_QST';
                                $ress = $this->db->fetchAll($query);
                                if(count($ress) > 0){
                            ?>
                                <td align="center"><?php echo $res_row['DCP_NOMABV']; ?></td>
                            <?php } } ?>
                                <td rowspan="2" align="center">Média: <?php echo $mel['PLA_POR']; ?></td>
                            </tr> 
                            <tr>
                            <?php 
                            $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM, d.DCP_NOMABV '
                                    .' FROM PUBSIM_RANALU p '
                                    .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                                    .' WHERE p.PLS_ID = ' . $row['PLS_ID']
                                    .' AND p.ALU_ID = ' . $mel['ALU_ID'];
                            $mel_alu = $this->db->fetchRow($query);
                            if($mel_alu['PLA_REDID'] > 0){
                            ?>
                                <td align="center"><?php echo $mel_alu['PLA_REDNTAPSO']; ?></td>
                            <?php  } ?>
                            <?php foreach($result as $res_row){ 

                                $qtd_acerto = 0;
                                $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                                        . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                                        .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                                        .' AND p.PLS_ID = '.$row['PLS_ID'].' AND r.PLS_ID = '.$row['PLS_ID']
                                        .' AND r.ALU_ID = '.$mel['ALU_ID']
                                        .' AND p.DCP_ID = r.DCP_ID '
                                        .' AND p.DCP_ID = '.$res_row['DCP_ID'].' AND r.DCP_ID = '.$res_row['DCP_ID']
                                        .' ORDER BY p.PSG_QST';
                                $ress = $this->db->fetchAll($query);
                                foreach($ress as $res){
                                    if($res['PSG_ALT'] == $res['PSR_ALT'] ){
                                        $qtd_acerto++;
                                    } 
                                }
                                if(count($ress) > 0){ 
                            ?>
                                <td align="center"><?php echo $qtd_acerto; ?></td>
                            <?php } } ?>
                            </tr> 
                        </table>
                    </div>
                     
                </td>
            </tr>
            <?php } ?>
        <?php } ?>
        </table>
    </div>
    
</div>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>